<?php
class SoftwaresController extends AppController {

	var $name = 'Softwares';

	function index() {
		$this->Software->recursive = 0;
		$this->set('softwares', $this->paginate());
	}

	function view($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid software', true));
			$this->redirect($this->referer());
		}
		$this->set('software', $this->Software->read(null, $id));
	}

	function add() {
		if (!empty($this->data)) {
			$this->Software->create();
			if ($this->Software->save($this->data)) {
				$this->Session->setFlash(__('The software has been saved', true));
				$this->redirect($this->referer());
			} else {
				$this->Session->setFlash(__('The software could not be saved. Please, try again.', true));
			}
		}
		$computers = $this->Software->Computer->find('list');
		$this->set(compact('computers'));
	}

	function edit($id = null) {
		if (!$id && empty($this->data)) {
			$this->Session->setFlash(__('Invalid software', true));
			$this->redirect($this->referer());
		}
		if (!empty($this->data)) {
			if ($this->Software->save($this->data)) {
				$this->Session->setFlash(__('The software has been saved', true));
				$this->redirect($this->referer());
			} else {
				$this->Session->setFlash(__('The software could not be saved. Please, try again.', true));
			}
		}
		if (empty($this->data)) {
			$this->data = $this->Software->read(null, $id);
		}
		$computers = $this->Software->Computer->find('list');
		$this->set(compact('computers'));
	}

	function delete($id = null) {
		if (!$id) {
			$this->Session->setFlash(__('Invalid id for software', true));
			$this->redirect($this->referer());
		}
		if ($this->Software->delete($id)) {
			$this->Session->setFlash(__('Software deleted', true));
			$this->redirect($this->referer());
		}
		$this->Session->setFlash(__('Software was not deleted', true));
		$this->redirect($this->referer());
	}
}
?>